package com.cskaoyan.app.wxservice.impl;

import com.cskaoyan.app.bean.po.MarketOrderExample;
import com.cskaoyan.app.enums.OrderCodeStat;
import com.cskaoyan.app.mapper.MarketOrderMapper;
import com.cskaoyan.app.wxservice.WxIndexService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

@Service
public class WxIndexServiceImpl implements WxIndexService {

    @Autowired
    private MarketOrderMapper orderMapper;

    @Override
    public Map<String, Long> getIndexMap(Integer userid) {
        MarketOrderExample example1 = new MarketOrderExample();
        MarketOrderExample.Criteria criteria1 = example1.createCriteria();
        criteria1.andUserIdEqualTo(userid)
                .andOrderStatusEqualTo(OrderCodeStat.UNPAID.getCode())
                .andDeletedEqualTo(false);

        MarketOrderExample example2 = new MarketOrderExample();
        MarketOrderExample.Criteria criteria2 = example2.createCriteria();
        criteria2.andUserIdEqualTo(userid)
                .andOrderStatusEqualTo(OrderCodeStat.PAID.getCode())
                .andDeletedEqualTo(false);

        MarketOrderExample example3 = new MarketOrderExample();
        MarketOrderExample.Criteria criteria3 = example3.createCriteria();
        criteria3.andUserIdEqualTo(userid)
                .andOrderStatusEqualTo(OrderCodeStat.SENT.getCode())
                .andDeletedEqualTo(false);

        MarketOrderExample example4 = new MarketOrderExample();
        MarketOrderExample.Criteria criteria4 = example4.createCriteria();
        criteria4.andUserIdEqualTo(userid)
                .andOrderStatusIn(Arrays.asList(OrderCodeStat.USER_RECEIVED.getCode(),
                        OrderCodeStat.SYS_RECEIVED.getCode()))
                .andCommentsGreaterThan((short) 0)
                .andDeletedEqualTo(false);

        long unPaid = orderMapper.countByExample(example1);
        long paid = orderMapper.countByExample(example2);
        long sent = orderMapper.countByExample(example3);
        long received = orderMapper.countByExample(example4);

        Map<String, Long> map = new HashMap<>();
        map.put("unpaid", unPaid);
        map.put("unship", paid);
        map.put("unrecv", sent);
        map.put("uncomment", received);
        return map;
    }
}
